import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RMISecurityManager;

import net.jini.lookup.entry.Name;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceItem;
import net.jini.core.discovery.LookupLocator;
import net.jini.core.entry.Entry;
import net.jini.core.lease.Lease;

public class HardDrive extends UnicastRemoteObject implements MassStorageDevice {

	public byte[] 	readFile(String name) throws RemoteException {
		System.out.println("HDD: reading from file <" + name + ">");
		return null;
	}
	
	public void 	writeFile(String name, byte[] data) throws RemoteException {
		System.out.println("HDD: writing to file <" + name + ">");
	}
	
	public HardDrive() throws RemoteException {
		super ();
	}
	
	public static void main (String[] args) {
		try {
			System.setSecurityManager (new RMISecurityManager ());
			
			ServiceItem serviceItem = new ServiceItem(null, new HardDrive(), null);

			LookupLocator lookup = new LookupLocator ("jini://localhost");
			ServiceRegistrar registrar  = lookup.getRegistrar();
			registrar.register(serviceItem, Lease.FOREVER);

			System.out.println("Hard Drive online");

		} catch (Exception e)
		{
			e.printStackTrace();
		}
	}

} 